package com.iplant.base.po.enums;

import com.iplant.base.utils.BaseConfigConstans;
import com.iplant.base.utils.general.StringUtils;

public enum DBSchemas implements BaseEnum {

	/**
	 * Default
	 */
	Default(0, "MySQL"),
	/**
	 * Basic
	 */
	Basic(1, "Basic"),
	/**
	 * APS
	 */
	APS(2, "APS"),
	/**
	 * MES
	 */
	MES(3, "MES"),

	/**
	 * WMS
	 */
	WMS(4, "WMS"),
	/**
	 * QMS
	 */
	PDM(5, "PDM"),
	/**
	 * ERP
	 */
	AMS(6, "AMS"),
	/**
	 * QMS
	 */
	QMS(7, "QMS")	,
	/**
	 * ERP
	 */
	ERP(9, "ERP"),
	/**
	 * TCM
	 */
	TCM(10, "TCM"),
	/**
	 *BPM
	 */
	BPM(11,"BPM");

	static {

		DBSchemas.Default.setRemark(BaseConfigConstans.DefaultDBName);

		DBSchemas.Basic.setRemark(BaseConfigConstans.BasicDBName);

		DBSchemas.APS.setRemark(BaseConfigConstans.APSDBName);

		DBSchemas.MES.setRemark(BaseConfigConstans.MESDBName);

		DBSchemas.WMS.setRemark(BaseConfigConstans.WMSDBName);

		DBSchemas.QMS.setRemark(BaseConfigConstans.QMSDBName);

		DBSchemas.AMS.setRemark(BaseConfigConstans.AMSDBName);

		DBSchemas.PDM.setRemark(BaseConfigConstans.PDMDBName);

		DBSchemas.ERP.setRemark(BaseConfigConstans.ERPDBName);

		DBSchemas.TCM.setRemark(BaseConfigConstans.TCMDBName);
		DBSchemas.BPM.setRemark(BaseConfigConstans.BPMDBName);
	}

	private int value;
	private String label;

	private String remark = "";

	private DBSchemas(int value, String label) {
		this.value = value;
		this.label = label;
	}

	private DBSchemas(int value, String label, String remark) {
		this.value = value;
		this.label = label;
		this.remark = remark;
	}

	/**
	 * 通过 value 的数值获取枚举实例
	 *
	 * @param val
	 * @return
	 */
	public static DBSchemas getEnumType(int val) {
		for (DBSchemas type : DBSchemas.values()) {
			if (type.getValue() == val) {
				return type;
			}
		}
		return Default;
	}

	public String getDBName() {
		return getDBName(DBEnumType.Default);
	}

	public String getTBName(String wTableName) {

		return StringUtils.Format("{0}.{1}", this.getDBName(DBEnumType.getEnumType(BaseConfigConstans.DBServerType)),
				wTableName);
	}

	public String getTBName(DBEnumType wDBEnumType, String wTableName) {
		return StringUtils.Format("{0}.{1}", this.getDBName(wDBEnumType), wTableName);
	}

	public String getDBName(DBEnumType wDBEnumType) {
		switch (wDBEnumType) {
		case Default:
			break;
		case MySQL:
			break;
		case SQLServer:
			return this.remark + ".dbo";
		case Oracle:
			break;
		case Access:
			break;
		default:
			break;
		}
		return this.remark;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

}
